home *** CD-ROM | disk | FTP | other *** search
/ CrystalVision Software Se… Wiki Wonder - Wikipedia / CrystalVision Software Services 703: The Wiki Wonder - Wikipedia.iso / 0703 / Educate / Complete Calc / Setup.exe / lib / tcl / auto.tcl next >
Encoding:
Text File  |  2006-10-25  |  8.3 KB  |  385 lines

  1.  
  2.  
  3. proc auto_reset {} {
  4. global auto_execs auto_index auto_oldpath
  5. foreach p [info procs] {
  6. if {[info exists auto_index($p)] && ![string match auto_* $p]
  7. && ([lsearch -exact {unknown pkg_mkIndex tclPkgSetup
  8. tcl_findLibrary pkg_compareExtension
  9. tclPkgUnknown tcl::MacOSXPkgUnknown
  10. tcl::MacPkgUnknown} $p] < 0)} {
  11. rename $p {}
  12. }
  13. }
  14. unset -nocomplain auto_execs auto_index auto_oldpath
  15. }
  16.  
  17.  
  18. proc tcl_findLibrary {basename version patch initScript enVarName varName} {
  19. upvar #0 $varName the_library
  20. global env errorInfo
  21.  
  22. set dirs {}
  23. set errors {}
  24.  
  25.  
  26. if {[info exists the_library] && $the_library ne ""} {
  27. lappend dirs $the_library
  28. } else {
  29.  
  30.  
  31.  
  32. if {[info exists env($enVarName)]} {
  33. lappend dirs $env($enVarName)
  34. }
  35.  
  36.  
  37. foreach d $::auto_path {
  38. lappend dirs [file join $d $basename$version]
  39. if {$::tcl_platform(platform) eq "unix"
  40. && $::tcl_platform(os) eq "Darwin"} {
  41. lappend dirs [file join $d $basename$version Resources Scripts]
  42. }
  43. }
  44.  
  45. set parentDir [file dirname [file dirname [info nameofexecutable]]]
  46. set grandParentDir [file dirname $parentDir]
  47. lappend dirs [file join $parentDir lib $basename$version]
  48. lappend dirs [file join $grandParentDir lib $basename$version]
  49. lappend dirs [file join $parentDir library]
  50.  
  51. if {1} {
  52. lappend dirs [file join $grandParentDir library]
  53. lappend dirs [file join $grandParentDir $basename$patch library]
  54. lappend dirs [file join [file dirname $grandParentDir]  $basename$patch library]
  55. }
  56. }
  57. array set seen {}
  58. foreach i $dirs {
  59. if {1 || [interp issafe]} {
  60. set norm $i
  61. } else {
  62. set norm [file normalize $i]
  63. }
  64. if {[info exists seen($norm)]} { continue }
  65. set seen($norm) ""
  66. lappend uniqdirs $i
  67. }
  68. set dirs $uniqdirs
  69. foreach i $dirs {
  70. set the_library $i
  71. set file [file join $i $initScript]
  72.  
  73.  
  74. if {[interp issafe] || [file exists $file]} {
  75. if {![catch {uplevel #0 [list source $file]} msg]} {
  76. return
  77. } else {
  78. append errors "$file: $msg\n$errorInfo\n"
  79. }
  80. }
  81. }
  82. unset -nocomplain the_library
  83. set msg "Can't find a usable $initScript in the following directories: \n"
  84. append msg "    $dirs\n\n"
  85. append msg "$errors\n\n"
  86. append msg "This probably means that $basename wasn't installed properly.\n"
  87. error $msg
  88. }
  89.  
  90.  
  91.  
  92. if {[interp issafe]} {
  93. return    ;# Stop sourcing the file here
  94. }
  95.  
  96.  
  97. proc auto_mkindex {dir args} {
  98. global errorCode errorInfo
  99.  
  100. if {[interp issafe]} {
  101. error "can't generate index within safe interpreter"
  102. }
  103.  
  104. set oldDir [pwd]
  105. cd $dir
  106. set dir [pwd]
  107.  
  108. append index "# Tcl autoload index file, version 2.0\n"
  109. append index "# This file is generated by the \"auto_mkindex\" command\n"
  110. append index "# and sourced to set up indexing information for one or\n"
  111. append index "# more commands.  Typically each line is a command that\n"
  112. append index "# sets an element in the auto_index array, where the\n"
  113. append index "# element name is the name of a command and the value is\n"
  114. append index "# a script that loads the command.\n\n"
  115. if {[llength $args] == 0} {
  116. set args *.tcl
  117. }
  118.  
  119. auto_mkindex_parser::init
  120. foreach file [eval [linsert $args 0 glob --]] {
  121. if {[catch {auto_mkindex_parser::mkindex $file} msg] == 0} {
  122. append index $msg
  123. } else {
  124. set code $errorCode
  125. set info $errorInfo
  126. cd $oldDir
  127. error $msg $info $code
  128. }
  129. }
  130. auto_mkindex_parser::cleanup
  131.  
  132. set fid [open "tclIndex" w]
  133. puts -nonewline $fid $index
  134. close $fid
  135. cd $oldDir
  136. }
  137.  
  138.  
  139. proc auto_mkindex_old {dir args} {
  140. global errorCode errorInfo
  141. set oldDir [pwd]
  142. cd $dir
  143. set dir [pwd]
  144. append index "# Tcl autoload index file, version 2.0\n"
  145. append index "# This file is generated by the \"auto_mkindex\" command\n"
  146. append index "# and sourced to set up indexing information for one or\n"
  147. append index "# more commands.  Typically each line is a command that\n"
  148. append index "# sets an element in the auto_index array, where the\n"
  149. append index "# element name is the name of a command and the value is\n"
  150. append index "# a script that loads the command.\n\n"
  151. if {[llength $args] == 0} {
  152. set args *.tcl
  153. }
  154. foreach file [eval [linsert $args 0 glob --]] {
  155. set f ""
  156. set error [catch {
  157. set f [open $file]
  158. while {[gets $f line] >= 0} {
  159. if {[regexp {^proc[     ]+([^     ]*)} $line match procName]} {
  160. set procName [lindex [auto_qualify $procName "::"] 0]
  161. append index "set [list auto_index($procName)]"
  162. append index " \[list source \[file join \$dir [list $file]\]\]\n"
  163. }
  164. }
  165. close $f
  166. } msg]
  167. if {$error} {
  168. set code $errorCode
  169. set info $errorInfo
  170. catch {close $f}
  171. cd $oldDir
  172. error $msg $info $code
  173. }
  174. }
  175. set f ""
  176. set error [catch {
  177. set f [open tclIndex w]
  178. puts -nonewline $f $index
  179. close $f
  180. cd $oldDir
  181. } msg]
  182. if {$error} {
  183. set code $errorCode
  184. set info $errorInfo
  185. catch {close $f}
  186. cd $oldDir
  187. error $msg $info $code
  188. }
  189. }
  190.  
  191.  
  192. namespace eval auto_mkindex_parser {
  193. variable parser ""          ;# parser used to build index
  194. variable index ""           ;# maintains index as it is built
  195. variable scriptFile ""      ;# name of file being processed
  196. variable contextStack ""    ;# stack of namespace scopes
  197. variable imports ""         ;# keeps track of all imported cmds
  198. variable initCommands ""    ;# list of commands that create aliases
  199.  
  200. proc init {} {
  201. variable parser
  202. variable initCommands
  203.  
  204. if {![interp issafe]} {
  205. set parser [interp create -safe]
  206. $parser hide info
  207. $parser hide rename
  208. $parser hide proc
  209. $parser hide namespace
  210. $parser hide eval
  211. $parser hide puts
  212. $parser invokehidden namespace delete ::
  213. $parser invokehidden proc unknown {args} {}
  214.  
  215.  
  216. $parser expose namespace
  217. $parser invokehidden rename namespace _%@namespace
  218. $parser expose eval
  219. $parser invokehidden rename eval _%@eval
  220.  
  221.  
  222. foreach cmd $initCommands {
  223. eval $cmd
  224. }
  225. }
  226. }
  227. proc cleanup {} {
  228. variable parser
  229. interp delete $parser
  230. unset parser
  231. }
  232. }
  233.  
  234.  
  235. proc auto_mkindex_parser::mkindex {file} {
  236. variable parser
  237. variable index
  238. variable scriptFile
  239. variable contextStack
  240. variable imports
  241.  
  242. set scriptFile $file
  243.  
  244. set fid [open $file]
  245. set contents [read $fid]
  246. close $fid
  247.  
  248. set contents [string map "$ \u0000" $contents]
  249.  
  250. set index ""
  251. set contextStack ""
  252. set imports ""
  253.  
  254. $parser eval $contents
  255.  
  256. foreach name $imports {
  257. catch {$parser eval [list _%@namespace forget $name]}
  258. }
  259. return $index
  260. }
  261.  
  262.  
  263. proc auto_mkindex_parser::hook {cmd} {
  264. variable initCommands
  265.  
  266. lappend initCommands $cmd
  267. }
  268.  
  269.  
  270. proc auto_mkindex_parser::slavehook {cmd} {
  271. variable initCommands
  272.  
  273.  
  274. lappend initCommands "\$parser eval [list $cmd]"
  275. }
  276.  
  277.  
  278. proc auto_mkindex_parser::command {name arglist body} {
  279. hook [list auto_mkindex_parser::commandInit $name $arglist $body]
  280. }
  281.  
  282.  
  283. proc auto_mkindex_parser::commandInit {name arglist body} {
  284. variable parser
  285.  
  286. set ns [namespace qualifiers $name]
  287. set tail [namespace tail $name]
  288. if {$ns eq ""} {
  289. set fakeName [namespace current]::_%@fake_$tail
  290. } else {
  291. set fakeName [namespace current]::[string map {:: _} _%@fake_$name]
  292. }
  293. proc $fakeName $arglist $body
  294.  
  295.  
  296. if {[string match *::* $name]} {
  297. set exportCmd [list _%@namespace export [namespace tail $name]]
  298. $parser eval [list _%@namespace eval $ns $exportCmd]
  299.  
  300.  
  301. set alias [namespace tail $fakeName]
  302. $parser invokehidden proc $name {args} "_%@eval {$alias} \$args"
  303. $parser alias $alias $fakeName
  304. } else {
  305. $parser alias $name $fakeName
  306. }
  307. return
  308. }
  309.  
  310.  
  311. proc auto_mkindex_parser::fullname {name} {
  312. variable contextStack
  313.  
  314. if {![string match ::* $name]} {
  315. foreach ns $contextStack {
  316. set name "${ns}::$name"
  317. if {[string match ::* $name]} {
  318. break
  319. }
  320. }
  321. }
  322.  
  323. if {[namespace qualifiers $name] eq ""} {
  324. set name [namespace tail $name]
  325. } elseif {![string match ::* $name]} {
  326. set name "::$name"
  327. }
  328.  
  329. return [string map "\u0000 $" $name]
  330. }
  331.  
  332.  
  333.  
  334. auto_mkindex_parser::command proc {name args} {
  335. variable index
  336. variable scriptFile
  337. append index [list set auto_index([fullname $name])]  [format { [list source [file join $dir %s]]}  [file split $scriptFile]] "\n"
  338. }
  339.  
  340.  
  341. auto_mkindex_parser::hook {
  342. if {![catch {package require tbcload}]} {
  343. if {[namespace which -command tbcload::bcproc] eq ""} {
  344. auto_load tbcload::bcproc
  345. }
  346. load {} tbcload $auto_mkindex_parser::parser
  347.  
  348.  
  349. auto_mkindex_parser::commandInit tbcload::bcproc {name args} {
  350. variable index
  351. variable scriptFile
  352. append index [list set auto_index([fullname $name])]  [format { [list source [file join $dir %s]]}  [file split $scriptFile]] "\n"
  353. }
  354. }
  355. }
  356.  
  357.  
  358. auto_mkindex_parser::command namespace {op args} {
  359. switch -- $op {
  360. eval {
  361. variable parser
  362. variable contextStack
  363.  
  364. set name [lindex $args 0]
  365. set args [lrange $args 1 end]
  366.  
  367. set contextStack [linsert $contextStack 0 $name]
  368. $parser eval [list _%@namespace eval $name] $args
  369. set contextStack [lrange $contextStack 1 end]
  370. }
  371. import {
  372. variable parser
  373. variable imports
  374. foreach pattern $args {
  375. if {$pattern ne "-force"} {
  376. lappend imports $pattern
  377. }
  378. }
  379. catch {$parser eval "_%@namespace import $args"}
  380. }
  381. }
  382. }
  383.  
  384. return
  385.